package com.rtx.wms.std.job.transfer;

import com.rtx.edi.model.api.bo.ApiMappingInfoBo;
import com.rtx.edi.platform.baseinfo.service.PlApiService;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.rtx.api.annotation.RtxJobAnnotation;
import com.rtx.api.quartz.job.BaseJob;
import com.rtx.wms.std.handler.transfer.mid.MidTransferHandler;

@Component
@DisallowConcurrentExecution
@RtxJobAnnotation(jobName = "ApiTransferToWmsJob",description = "调拨单中间表写入wms",cron = "0/10 * * * * ?")
public class ApiTransferToWmsJob implements BaseJob {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MidTransferHandler midTransferHandler;

    @Autowired
    PlApiService plApiService;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
//    	try {
//    		midTransferHandler.handlerMidToWms("wmwhse1");
//		} catch (Exception e) {
//			logger.error("仓库{}调拨单中间表写入WMS异常","wmwhse1",e);
//		}
        ApiMappingInfoBo bo = null;
        try {
            JobDataMap dataMap = context.getJobDetail().getJobDataMap();

            String mappingCode = dataMap.get("apiMappingCode")+"";

            bo = plApiService.getApiMappingInfo(mappingCode);
        } catch (Exception e) {
            logger.error("",e);
        }

        try {
            midTransferHandler.handlerMidToWms("wmwhse1",bo);
        } catch (Exception e) {
            logger.error("仓库{}出库单从中间表写入WMS异常","wmwhse1",e);
        }
    	
    }
}
